<template>
  <div>
    <!-- 导航栏 -->
    <van-nav-bar title="患者详情"
                 @click-left="$router.back(-1)">
      <template #left>
        <img class="icon_right"
             src="@/assets/img/down_left.png"
             alt="">
      </template>
    </van-nav-bar>
    <div class="box">

      <div class="title">
        <span class="i"></span>
        <span style="color:#4182FF">患者信息</span>
      </div>
      <button class="btn" @click="relieveBind">解除关联</button>
      <div class="info">
        <van-cell title="姓名"
                  :value="userInfo.nickname" />
        <van-cell title="癌种"
                  :value="userInfo.carcinoma" />
        <van-cell title="年龄"
                  :value="userInfo.age" />
        <van-cell title="性别"
                  :value="userInfo.gender == 0 ? '女' : '男'" />
        <div class="more"
               @click="moreInfo">更多信息<img src="@/assets/img/more_r.png"
               alt=""></div>
      </div>
      <div class="title">
        <span class="i"></span>
        <span>CINV综合管理</span>
      </div>

      <!-- CINV综合管理 -->
      <van-list v-model="loading"
                :finished="finished"
                finished-text="END"
                @load="getData">
        <div class="cycle">
          <div class="items"
               :class="{ 'active_item': i.color === 'green'}"
               @click="cycleDetail(i)"
               v-for="(i,ins) in list"
               :key="ins">
            <span>{{i.createtime}}</span>
            <span :style="{ 'color': i.color === 'red' ? '#FD436C' : ''}">{{i.situation || '暂无'}}</span>
          </div>
          <!-- <div class="items active_item">
            <span>2021-06-15</span>
            <span>控制良好</span>
          </div> -->
        </div>
      </van-list>

    </div>
  </div>
</template>
<script>
import { patientDetail, treatmentCycle, removeAssociate } from '@/api/medical'
export default {
  data () {
    return {
      id: '',
      userInfo: {},
      list: [],
      loading: false,
      finished: false,
      parameter: {
        page_index: 0,
        page_size: 20
      }
    }
  },
  mounted () {
    this.id = this.$route.query.id
    this.patientDetail()
    // this.treatmentCycle()
  },
  methods: {
    cycleDetail (item) {
      this.$router.push({
        path: '/user/Information',
        query: {
          id: item.id,
          date: item.createtime
        }
      })
    },
    // 解除关联
    async relieveBind () {
      const { code, msg } = await removeAssociate({ patients_id: this.id })
      if (code !== 1) return this.$toast.fail(msg)
      this.$toast.success('解除关联成功')
      setTimeout(() => {
        this.$router.back()
      }, 1000)
    },
    // 医护查看既往治疗周期
    async getData () {
      // TODO TEST vant-list 分页逻辑
      this.parameter.page_index += 1
      this.parameter.patients_id = this.id
      const { code, msg, data } = await treatmentCycle(this.parameter)
      this.loading = false
      if (code !== 1) {
        this.finished = true
        return this.$toast.fail(msg)
      }
      if (this.parameter.page_index === 1) this.list = []
      this.list.push(...data.data || [])
      if (this.list.length >= data.total) {
        this.finished = true
      }
    },
    // 查看患者详情
    async patientDetail () {
      const { code, msg, data } = await patientDetail({ id: this.id })
      if (code !== 1) return this.$toast.fail(msg)
      this.userInfo = data
    },
    // 更多信息
    moreInfo () {
      this.$router.push({
        path: '/user/moreInfo',
        query: this.userInfo
      })
    }
  }

}
</script>
<style scoped lang='less'>
// 标题
.title {
  width: 100%;
  height: 34px;
  .i {
    display: inline-block;
    margin-right: 5px;
    width: 3px;
    height: 14px;
    background: linear-gradient(180deg, #3eb3ff 0%, #436eff 100%);
    opacity: 1;
  }
  span {
    display: inline-block;
    height: 22px;
    font-size: 16px;
    font-family: PingFang SC;
    font-weight: 600;
    line-height: 22px;
    color: #161616;
    opacity: 1;
  }
}
.icon_right {
  width: 12px;
  height: 21px;
  vertical-align: middle;
}
.box {
  width: 100%;
  height: 100vh;
  margin-top: 40px;
  background: #f7f8fa;
  padding: 10px 20px;
  box-sizing: border-box;
  .btn {
    width: 89px;
    height: 28px;
    background: linear-gradient(180deg, #3eb3ff 0%, #436eff 100%);
    font-size: 14px;
    font-family: PingFang SC;
    font-weight: 400;
    color: #ffffff;
    letter-spacing: 1px;
    border-radius: 4px;
    border: none;
  }
  .info {
    width: 100%;
    border-radius: 8px;
    padding: 8px;
    margin-top: 18px;
    box-sizing: border-box;
    background-color: #fff;
    /deep/.van-cell__title {
      font-weight: 600;
    }
    .more {
      font-size: 15px;
      font-family: PingFang SC;
      font-weight: 400;
      line-height: 30px;
      color: #4182ff;
      padding-left: 15px;
      margin-top: 14px;
      img {
        width: 13px;
        height: 14px;
        margin-left: 5px;
        vertical-align: middle;
      }
    }
  }
  .cycle {
    width: 100%;
    margin-bottom: 25px;
    .items {
      width: 100%;
      height: 54px;
      margin: 10px auto;
      border-radius: 8px;
      background: url("../../assets/img/zq_bj1.png") no-repeat;
      background-size: 100%;
    }
    .active_item {
      background: url("../../assets/img/zq_bj2.png") no-repeat;
      background-size: 100%;
    }
    span {
      display: inline-block;
      width: 50%;
      height: 54px;
      line-height: 54px;
      text-align: center;
      font-size: 15px;
      color: #ffffff;
      font-weight: 600;
    }
  }
}
</style>
